
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render
import json
class Controller:
    @staticmethod
    def show_json(data,state=True,info=None):
        ret = {
            "code": state
            , "data": data
            , "use_time": 6666
        }
        if info is not None:
            ret.update({"info":info})
        return HttpResponse(json.dumps(ret))
    @staticmethod
    def get_data_base_dir():
        #return data,info
        from Typelab.settings import BASE_DIR
        import os.path
        _path = BASE_DIR+"/Typelab/dss_config.json"
        default = (BASE_DIR + "/Data/").replace('\\','/')
        if os.path.exists(_path):
            try:
                c = open(_path,'r')
                config = json.loads(c.read())
                c.close()
                return config['DataPath'],'success',True
            except Exception as e:
                return None,default,False
        return None,default,False
    @staticmethod
    def get_database_dir():
        #return data,info
        from Typelab.settings import BASE_DIR
        import os.path
        _path = BASE_DIR+"/Typelab/dss_config.json"
        if os.path.exists(_path):
            try:
                c = open(_path,'r')
                config = json.loads(c.read())
                c.close()
                return config['DataPath']
            except Exception as e:
                return None